﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;
using HZ.MBSM.Model;
public partial class WebLowUpdate : System.Web.UI.Page
{
    private string LawId;
    public string strName1, strContent1;
    protected void Page_Load(object sender, EventArgs e)
    {
        string strName, strContent;
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAdmin);
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney);
        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {
            LawId = SysFun.IsSQL(Request.QueryString["LawId"].ToString());
            if (!this.IsPostBack)
            {
                Db db = new Db(false);
                Grove.ORM.ObjectOperator oo = db.GetObjectOperator();
                HZ.MBSM.Model.law law = (HZ.MBSM.Model.law)oo.Retrieve(typeof(HZ.MBSM.Model.law), LawId);
                txtConferdate.Text = law.ConferDate.ToString();
                txtAddDate.Text = SysFun.ToTrim(law.AddDate);
                txtAddDate.Visible = false;
                txtLawId.Text = SysFun.ToTrim(law.LawId);
                txtLawId.Visible = false;
                chkIsDisplay.Checked = (bool)law.IsDisplay;
                strName1 = law.Title;
                strContent1 = law.Content;
                oo.Dispose();
            }
            strName = SysFun.ToTrim(Request.Form["txtName"]);
            strContent = SysFun.ToTrim(Request.Form["txtContentHtml"]);
            if (strName != "" && strContent != "")
            {
                //修改
                LawId = SysFun.ToTrim(txtLawId.Text);

                Db db = new Db();
                Grove.ORM.ObjectOperator oo = db.GetObjectOperator();
                HZ.MBSM.Model.law law = (HZ.MBSM.Model.law)oo.Retrieve(typeof(HZ.MBSM.Model.law), LawId);
                if (SysFun.ToTrim(txtAddDate.Text) != "")
                    law.AddDate = Convert.ToDateTime(txtAddDate.Text);
                law.Title = strName;
                law.Content = strContent.Replace("\r\n", "");
                law.ConferDate = Convert.ToDateTime(txtConferdate.Text);
                law.IsDisplay = Convert.ToBoolean(chkIsDisplay.Checked);
                oo.Update(law);
                oo.Dispose();
                db.Close();
                Response.Write("<script>alert('保存成功！！！');</script>");
                HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
                HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "law", law.Title + "|" + law.Content + "|" + law.ConferDate + "|" + law.AddDate + "|" + law.IsDisplay, "../Magage/WeblawUpdate.aspx");

                Response.Write("<script>window.opener.location.reload();window.close();</script>");
            }

        }
       
    }
    //protected void Button1_Click(object sender, EventArgs e)
    //{
    //    LawId = SysFun.ToTrim(txtLawId.Text);

    //    Db db = new Db();
    //    Grove.ORM.ObjectOperator oo = db.GetObjectOperator();
    //    HZ.MBSM.Model.law law = (HZ.MBSM.Model.law)oo.Retrieve(typeof(HZ.MBSM.Model.law), LawId);
    //    if (SysFun.ToTrim(txtAddDate.Text) != "")
    //        law.AddDate = Convert.ToDateTime(txtAddDate.Text);
    //    law.Title = txtTitle.Text;
    //    law.Content = txtContent.Text;
    //    law.ConferDate = Convert.ToDateTime(txtConferdate.Text);
    //    law.IsDisplay = Convert.ToBoolean(chkIsDisplay.Checked);
    //    oo.Update(law);
    //    oo.Dispose();
    //    Response.Write("<script>alert('保存成功！！！');</script>");

    //    Response.Write("<script>window.opener.location.reload();window.close();</script>");
    //}

   protected void Button2_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.opener.location.reload();window.close();</script>");

    }
}
